1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10
11
12 namespace SoftQuanLyNhaHang.Views
13 {
14 public partial class uctNhapKho : UserControl
15 {
16 public uctNhapKho()
17 {
18 InitializeComponent();
19
20 HienThiControl(false);
21
22 //Ẩn nút xóa khi không ở tab danh sách nhập kho
23 btnXoa.Enabled = false;
24 btnSua.Enabled = false;
25 pnlPhanTrang.Visible = false;
26
27 }
28
29 int flag = 0;
30 int _idNhapKho = 0;
31 string _maSanPham = "";
32 string _tenSanPham = "";
33 int _soLuong = 0;
34 int _donViTinhId = 0;
35 string _tenDonViTinh = "";
36 string _giaNhap = "0";
37 string _ngaySanXuat = "";
38 string _hanSuDung = "";
39 string _hoVaTen = "";
40 string _soDienThoai = "";
41 string _diaChi = "";
42 string _ghiChu = "";
43 string _thanhTien = "";
44 string tTien = "";
45 bool sanpham_cotrongttsp = true;
46 string _giaBanLe = "0";
47 string _giaBanBuon = "0";
48 int _soLuongBanLe = 0;
49 int _donViTinhBanLeId = 0;
50 string _tenDonViTinhBanLe = string.Empty;
51 DateTime _ngayTao = DateTime.Now;
52
53 DataTable dt = new DataTable();
54
55 int _pageSize = 15;
56 int _pageIndex = 1;
57 int _tongSoBanGhi = 0;
58 int _stt = 0;
59 int _tongSoTrang = 1;
60
61 //khởi tạo gọi trong menuscript
62 public static uctNhapKho uctNk = new uctNhapKho();
63
64 private void ShowDonViTinh_ComboBox()
65 {
66 Dictionary<string, string> comboSource = new Dictionary<string, string>();
67 comboSource.Add("0", "-- Chọn đơn vị tính --");
68 DataTable dtdvt = new DataTable();
69 //dtdvt = Models.NhapKhoMod.FillDataSet_getTenDonViTinh().Tables[0];
70 if (dtdvt.Rows.Count > 0)
71 {
72 foreach (DataRow item in dtdvt.Rows)
73 {
74 comboSource.Add(item["IdDonViTinh"].ToString(), item["TenDonViTinh"].ToString());
75 }
76
77 }
78 cmbDonViTinh.DataSource = new BindingSource(comboSource, null);
79 cmbDonViTinh.DisplayMember = "Value";
80 cmbDonViTinh.ValueMember = "Key";
81 }
82
83 void loadcontrol()
84 {
85
86 this.ShowDonViTinh_ComboBox();
87
88 //cmbDonViTinh.DataSource = Models .NhapKhoMod.FillDataSet_getTenDonViTinh().Tables[0];
89 //cmbDonViTinh.DisplayMember = "TenDonViTinh";
90 //cmbDonViTinh.ValueMember = "IdDonViTinh";
91
92 cmbSoDongHienThi.Items.Clear();
93 cmbSoDongHienThi.Items.Add("15");
94 cmbSoDongHienThi.Items.Add("30");
95 cmbSoDongHienThi.Items.Add("50");
96 cmbSoDongHienThi.Items.Add("100");
97 cmbSoDongHienThi.SelectedItem = "15";
98 }
99
100 public void HienThiControl(bool e)
101 {
102 txtTenSanPham.Enabled = e;
103 txtSoLuong.Enabled = e;
104 txtGiaNhap.Enabled = e;
105 cmbDonViTinh.Enabled = e;
106 txtHanSuDung.Enabled = e;
107 txtNgaySanXuat.Enabled = e;
108 txtGhiChu.Enabled = e;
109 txtHoTen.Enabled = e;
110 txtSoDienThoai.Enabled = e;
111 txtDiaChi.Enabled = e;
112 txtGiaBanLe.Enabled = e;
113 txtGiaBanBuon.Enabled = e;
114 }
115
116 public void HienThiDanhSachNhapKho()
117 {
118
119 //dgvDanhSachNhapKho.DataSource = // Models.NhapKhoMod.FillDataSet_get_tbl_NhapKho_GetAll().Tables[0];
120 //dgvDanhSachNhapKho.Dock = DockStyle.Fill;
121 //dgvDanhSachNhapKho.RowHeadersVisible = false;
122 //dgvDanhSachNhapKho.BorderStyle = BorderStyle.Fixed3D;
123 dgvDanhSachNhapKho.Rows.Clear();
124 //dt = Controllers.NhapKhoCtrl.FillDataSet_tbl_NhapKho_Search(_pageSize, _pageIndex).Tables[0];
125
126 if (dt.Rows.Count > 0)
127 {
128
129
130
131 foreach (DataRow item in dt.Rows)
132 {
133
134 _stt += 1;
135 int n = dgvDanhSachNhapKho.Rows.Add();
136
137 dgvDanhSachNhapKho.Rows[n].Cells[0].Value = item["IdNhapKho"].ToString();
138 dgvDanhSachNhapKho.Rows[n].Cells[1].Value = _stt.ToString();
139 dgvDanhSachNhapKho.Rows[n].Cells[2].Value = item["MaSanPham"].ToString();
140 dgvDanhSachNhapKho.Rows[n].Cells[3].Value = item["TenSanPham"].ToString();
141 dgvDanhSachNhapKho.Rows[n].Cells[4].Value = item["SoLuong"].ToString();
142 dgvDanhSachNhapKho.Rows[n].Cells[5].Value = item["TenDonViTinh"].ToString();
143 dgvDanhSachNhapKho.Rows[n].Cells[6].Value = item["GiaNhap"].ToString();
144 dgvDanhSachNhapKho.Rows[n].Cells[7].Value = item["ThanhTien"].ToString();
145 dgvDanhSachNhapKho.Rows[n].Cells[8].Value = item["HanSuDung"].ToString();
146 dgvDanhSachNhapKho.Rows[n].Cells[9].Value = item["NgaySanXuat"].ToString();
147 dgvDanhSachNhapKho.Rows[n].Cells[10].Value = item["HoVaTen"].ToString();
148 dgvDanhSachNhapKho.Rows[n].Cells[11].Value = item["SoDienThoai"].ToString();
149 dgvDanhSachNhapKho.Rows[n].Cells[12].Value = item["DiaChi"].ToString();
150 dgvDanhSachNhapKho.Rows[n].Cells[13].Value = item["GhiChu"].ToString();
151 dgvDanhSachNhapKho.Rows[n].Cells[14].Value = item["GiaBanLe"].ToString();
152 dgvDanhSachNhapKho.Rows[n].Cells[15].Value = item["GiaBanBuon"].ToString();
153 dgvDanhSachNhapKho.Rows[n].Cells[16].Value = item["TongSoBanGhi"].ToString();
154 dgvDanhSachNhapKho.Rows[n].Cells[17].Value = "false";
155
156 // if (item["TrangThai"].ToString() == "1")
157 // {
158 // tthai = "Sử dụng";
159 // }
160 // else
161 // {
162 // tthai = "không";
163 // }
164
165 // dgvDanhSachNhapKho.Rows[n].Cells[3].Value = tthai;
166 // dgvDanhSachNhapKho.Rows[n].Cells[4].Value = "false";
167 //dgvDanhSachNhapKho.Rows[n].Cells[5].Value = item["MaDonViTinh"].ToString();
168 //dgvDanhSachNhapKho.Rows[n].Cells[6].Value = item["TongSoBanGhi"].ToString();
169
170 }
171 _tongSoBanGhi = Int32.Parse(dgvDanhSachNhapKho.Rows[0].Cells[16].Value.ToString());
172 HienThiPhanTrang(_tongSoBanGhi, _pageSize, _pageIndex);
173
174
175 }
176 }
177
178 private void HienThiPhanTrang(int tongSoBanGhi, int pageSize, int pageIndex)
179 {
180 if (tongSoBanGhi <= pageSize)
181 {
182 pnlPhanTrang.Visible = false;
183 }
184 else
185 {
186
187 }
188 }
189
190 private void uctNhapKho_Load(object sender, EventArgs e)
191 {
192 loadcontrol();
193 //
194 }
195
196 void dis_end(bool e)
197 {
198 txtMaSanPham.Enabled = e;
199 btnLuu.Enabled = e;
200 btnHuy.Enabled = e;
201 btnXoa.Enabled = !e;
202 btnSua.Enabled = !e;
203 }
204
205 //giữ lại thông tin nhà cung cấp
206 void clearThongTinLienHe()
207 {
208 txtHoTen.Text = "";
209 txtSoDienThoai.Text = "";
210 txtDiaChi.Text = "";
211 }
212 void clearThongTinSanPham()
213 {
214 //txtMaSanPham.Text = "";
215 txtTenSanPham.Text = "";
216 txtSoLuong.Text = "";
217 txtGiaNhap.Text = "";
218 txtNgaySanXuat.Text = "";
219 txtHanSuDung.Text = "";
220 txtGhiChu.Text = "";
221 txtGiaBanLe.Text = "";
222 txtGiaBanBuon.Text = "";
223 }
224
225 void bingding()
226 {
227 txtMaSanPham.DataBindings.Clear();
228 txtMaSanPham.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "MaSanPham");
229 txtTenSanPham.DataBindings.Clear();
230 txtTenSanPham.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "TenSanPham");
231 txtSoLuong.DataBindings.Clear();
232 txtSoLuong.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "SoLuong");
233 txtGiaNhap.DataBindings.Clear();
234 txtGiaNhap.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "GiaNhap");
235 txtNgaySanXuat.DataBindings.Clear();
236 txtNgaySanXuat.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "NgaySanXuat");
237 txtHanSuDung.DataBindings.Clear();
238 txtHanSuDung.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "HanSuDung");
239 txtGhiChu.DataBindings.Clear();
240 txtGhiChu.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "GhiChu");
241 txtHoTen.DataBindings.Clear();
242 txtHoTen.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "HoVaTen");
243 txtSoDienThoai.DataBindings.Clear();
244 txtSoDienThoai.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "SoDienThoai");
245 txtDiaChi.DataBindings.Clear();
246 txtDiaChi.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "DiaChi");
247 cmbDonViTinh.DataBindings.Clear();
248 cmbDonViTinh.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "TenDonViTinh");
249 txtGiaBanLe.DataBindings.Clear();
250 txtGiaBanLe.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "GiaBanLe");
251 txtGiaBanBuon.DataBindings.Clear();
252 txtGiaBanBuon.DataBindings.Add("Text", dgvDanhSachNhapKho.DataSource, "GiaBanBuon");
253
254 }
255
256 private void HienThiRaTextBox_ByGetDaTa(string tensanpham, int soluong, string donvitinh, string gianhap, string hansudung, string ngaysanxuat, string ghichu, string hovaten, string sodienthoai, string diachi, string giabanle, string giabanbuon)
257 {
258 txtTenSanPham.Text = tensanpham;
259 txtSoLuong.Text = soluong.ToString();
260 txtGiaNhap.Text = gianhap;
261 cmbDonViTinh.Text = donvitinh;
262 txtHanSuDung.Text = hansudung;
263 txtNgaySanXuat.Text = ngaysanxuat;
264 txtGhiChu.Text = ghichu;
265 txtHoTen.Text = hovaten;
266 txtSoDienThoai.Text = sodienthoai;
267 txtDiaChi.Text = diachi;
268 txtGiaBanLe.Text = giabanle;
269 txtGiaBanBuon.Text = giabanbuon;
270 }
271
272 private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
273 {
274
275 }
276
277 private void btnThemMoi_Click(object sender, EventArgs e)
278 {
279
280 }
281
282 private void btnSua_Click(object sender, EventArgs e)
283 {
284
285 if (_idNhapKho > 0)
286 {
287
288 try
289 {
290 _maSanPham = txtMaSanPham.Text;
291 }
292 catch { }
293
294 try
295 {
296 _tenSanPham = txtTenSanPham.Text;
297 }
298 catch { }
299
300 try
301 {
302 _soLuong = Int32.Parse(txtSoLuong.Text);
303 }
304 catch { }
305
306 try
307 {
308 _donViTinhId = (int)cmbDonViTinh.SelectedValue;
309 }
310 catch { }
311
312 try
313 {
314 _tenDonViTinh = cmbDonViTinh.GetItemText(cmbDonViTinh.SelectedItem);
315 }
316 catch { }
317
318 try
319 {
320 _giaNhap = txtGiaNhap.Text.Trim();
321 }
322 catch { }
323
324 try
325 {
326 _hanSuDung = txtHanSuDung.Text;
327 }
328 catch { }
329
330 try
331 {
332 _ngaySanXuat = txtNgaySanXuat.Text;
333 }
334 catch { }
335
336
337 try
338 {
339 _hoVaTen = txtHoTen.Text;
340 }
341 catch { }
342
343 try
344 {
345 _soDienThoai = txtSoDienThoai.Text;
346 }
347 catch { }
348
349 try
350 {
351 _diaChi = txtDiaChi.Text;
352 }
353 catch { }
354
355 try
356 {
357 _ghiChu = txtGhiChu.Text;
358 }
359 catch { }
360
361 try
362 {
363 _thanhTien = tTien;
364 }
365 catch
366 {
367 }
368
369 try
370 {
371 _giaBanLe = txtGiaBanLe.Text.Trim();
372 }
373 catch { }
374
375 try
376 {
377 _giaBanBuon = txtGiaBanBuon.Text.Trim();
378 }
379 catch { }
380
381 int i = 0;
382 //i = Controllers.NhapKhoCtrl.UpdateNhapKho(_idNhapKho, _maSanPham, _tenSanPham, _soLuong, _donViTinhId, _tenDonViTinh, _giaNhap, _ngaySanXuat, _hanSuDung, _hoVaTen, _soDienThoai, _diaChi, _ghiChu, _thanhTien, _giaBanLe, _giaBanBuon, _ngayTao);
383 if (i > 0)
384 {
385 MessageBox.Show(" Sửa thành công");
386 this.HienThiDanhSachNhapKho();
387 }
388 else
389 {
390 MessageBox.Show("Sửa không thành công");
391 }
392 }
393 }
394
395 private void btnXoa_Click(object sender, EventArgs e)
396 {
397 if (string.IsNullOrEmpty(txtMaSanPham.Text.Trim()) && string.IsNullOrEmpty(txtTenSanPham.Text.Trim()))
398 {
399 MessageBox.Show("Bạn chưa chọn sản phẩm để xóa!");
400 return;
401 }
402 foreach (DataGridViewRow dataRow in dgvDanhSachNhapKho.Rows)
403 {
404 if (bool.Parse(dataRow.Cells[17].Value.ToString()))
405 {
406 DialogResult dr = MessageBox.Show("Bạn có chắc chắn xóa?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
407 if (dr == DialogResult.Yes)
408 {
409 int i = 0;
410 //i = Controllers.NhapKhoCtrl.DeleteNhapKho(Int32.Parse(dataRow.Cells[0].Value.ToString()));
411
412 if (i > 0)
413 {
414 MessageBox.Show(" Xóa thành công");
415 this.HienThiDanhSachNhapKho();
416 this.clearThongTinLienHe();
417 this.clearThongTinSanPham();
418 txtMaSanPham.Text = "";
419 }
420 else
421 {
422 MessageBox.Show("Xóa không thành công");
423 }
424 }
425 else
426 {
427 return;
428 }
429 }
430 }//end foreach
431
432
433
434 }
435
436 private void btnHuy_Click(object sender, EventArgs e)
437 {
438 DialogResult dr = MessageBox.Show("Bạn muốn hủy sản phẩm?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
439 if (dr == DialogResult.Yes)
440 {
441 txtMaSanPham.Text = string.Empty;
442
443 clearThongTinLienHe();
444
445 clearThongTinSanPham();
446
447 }
448 else
449 {
450 return;
451 }
452
453 }
454
455 private void btnLuu_Click(object sender, EventArgs e)
456 {
457
458 try
459 {
460 _maSanPham = txtMaSanPham.Text;
461 }
462 catch{}
463
464 try
465 {
466 _tenSanPham = txtTenSanPham.Text;
467 }
468 catch { }
469
470 try
471 {
472 _soLuong = Int32.Parse(txtSoLuong.Text);
473 }
474 catch{}
475
476 try
477 {
478 _donViTinhId = (int)cmbDonViTinh.SelectedValue;
479 }
480 catch { }
481
482 try
483 {
484 _tenDonViTinh = cmbDonViTinh.GetItemText(cmbDonViTinh.SelectedItem);
485 }
486 catch { }
487
488 try
489 {
490 _giaNhap = txtGiaNhap.Text.Trim();
491 }
492 catch{}
493
494 try
495 {
496 _hanSuDung = txtHanSuDung.Text;
497 }
498 catch { }
499
500 try
501 {
502 _ngaySanXuat = txtNgaySanXuat.Text;
503 }
504 catch{}
505
506
507 try
508 {
509 _hoVaTen = txtHoTen.Text;
510 }
511 catch { }
512
513 try
514 {
515 _soDienThoai = txtSoDienThoai.Text;
516 }
517 catch { }
518
519 try
520 {
521 _diaChi = txtDiaChi.Text;
522 }
523 catch { }
524
525 try
526 {
527 _ghiChu = txtGhiChu.Text;
528 }
529 catch { }
530
531 try
532 {
533 _thanhTien = tTien;
534 }
535 catch
536 {
537 }
538
539 try
540 {
541 _giaBanLe = txtGiaBanLe.Text.Trim();
542 }
543 catch { }
544
545 try
546 {
547 _giaBanBuon = txtGiaBanBuon.Text.Trim();
548 }
549 catch { }
550
551 if (flag == 0)
552 {
553
554
555 if (_maSanPham == "" || _tenSanPham == "")
556 {
557 MessageBox.Show("Hãy nhập đầy đủ thông tin");
558 }
559 else
560 {
561 int i = 0;
562 //i = Controllers.NhapKhoCtrl.InsertNhapKho(_idNhapKho, _maSanPham, _tenSanPham, _soLuong, _donViTinhId, _tenDonViTinh, _giaNhap, _ngaySanXuat, _hanSuDung, _hoVaTen, _soDienThoai, _diaChi, _ghiChu, _thanhTien, _giaBanLe, _giaBanBuon, _ngayTao);
563 if (i > 0)
564 {
565 //Thêm sản phẩm vào bảng thông tin sp của hệ thống
566 if (sanpham_cotrongttsp == false)
567 {
568 Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(0, _maSanPham, _tenSanPham, 0, "", _donViTinhId, _tenDonViTinh, _ghiChu, _ngayTao, 1);
569 }
570
571 MessageBox.Show("Thêm mới thành công");
572 //uctNhapKho_Load(sender, e);
573
574 if (!string.IsNullOrEmpty(txtMaSanPham.Text.Trim()) && !string.IsNullOrEmpty(txtTenSanPham.Text.Trim()))
575 {
576 this.SanPhamVuaThemMoi();
577 }
578
579 //Xóa text trong controll
580 clearThongTinSanPham();
581 txtMaSanPham.Text = "";
582 }
583 else
584 {
585 MessageBox.Show("Thêm mới không thành công");
586 }
587 }
588 }
589 else
590 {
591
592 }
593
594
595
596
597
598 }
599
600 private void SanPhamVuaThemMoi ()
601 {
602 //Hiển thị danh sách sản phẩm vừa thêm
603 dgvSanPhamVuaNhap.ColumnCount = 15;
604
605 dgvSanPhamVuaNhap.Columns[0].Name = "STT";
606 dgvSanPhamVuaNhap.Columns[1].Name = "Mã sản phẩm";
607 dgvSanPhamVuaNhap.Columns[2].Name = "Tên sản phẩm";
608 dgvSanPhamVuaNhap.Columns[3].Name = "SL";
609 dgvSanPhamVuaNhap.Columns[4].Name = "ĐVT";
610 dgvSanPhamVuaNhap.Columns[5].Name = "Giá Nhập";
611 dgvSanPhamVuaNhap.Columns[6].Name = "Thành tiền";
612 dgvSanPhamVuaNhap.Columns[7].Name = "Giá bán lẻ";
613 dgvSanPhamVuaNhap.Columns[8].Name = "Giá bán buôn";
614
615 dgvSanPhamVuaNhap.Columns[9].Name = "HSD";
616 dgvSanPhamVuaNhap.Columns[10].Name = "NSX";
617 dgvSanPhamVuaNhap.Columns[11].Name = "Họ và tên";
618 dgvSanPhamVuaNhap.Columns[12].Name = "SĐT";
619 dgvSanPhamVuaNhap.Columns[13].Name = "Địa chỉ";
620 dgvSanPhamVuaNhap.Columns[14].Name = "Ghi chú";
621
622 string[] row = new string[] { "1", _maSanPham, _tenSanPham, _soLuong.ToString(), _tenDonViTinh, _giaNhap, _thanhTien, _giaBanLe, _giaBanBuon, _hanSuDung, _ngaySanXuat, _hoVaTen, _soDienThoai, _diaChi, _ghiChu };
623 dgvSanPhamVuaNhap.Rows.Add(row);
624 }
625
626 //Chỉ cho nhập số
627 //stackoverflow.com/questions/463299/how-do-i-make-a-textbox-that-only-accepts-numbers
628 private void txtSoLuong_KeyPress(object sender, KeyPressEventArgs e)
629 {
630 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
631 {
632 e.Handled = true;
633 }
634
635 // only allow one decimal point
636 if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
637 {
638 e.Handled = true;
639 }
640 }
641
642 private void txtGiaNhap_KeyPress(object sender, KeyPressEventArgs e)
643 {
644 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
645 {
646 e.Handled = true;
647 }
648
649 // only allow one decimal point
650 if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
651 {
652 e.Handled = true;
653 }
654 }
655
656 //stackoverflow.com/questions/18593799/thousand-separator-in-c-sharp-winforms-texbox
657 private void txtGiaNhap_TextChanged(object sender, EventArgs e)
658 {
659 try
660 {
661 string value = txtGiaNhap.Text.Replace(",", "");
662 ulong ul;
663 if (ulong.TryParse(value, out ul))
664 {
665 txtGiaNhap.TextChanged -= txtGiaNhap_TextChanged;
666 txtGiaNhap.Text = string.Format("{0:#,#}", ul);
667 txtGiaNhap.SelectionStart = txtGiaNhap.Text.Length;
668 txtGiaNhap.TextChanged += txtGiaNhap_TextChanged;
669 }
670 }
671 catch
672 {
673 //ExceptionkeeperBll.LogFileWrite(ex);
674 }
675
676 ThanhTien(txtSoLuong.Text.Trim(), txtGiaNhap.Text.Trim());
677 }
678
679 private void chkThanhTien_CheckedChanged(object sender, EventArgs e)
680 {
681
682 }
683
684 private void ThanhTien(string _sLuong, string _gNhap)
685 {
686 if (txtSoLuong.Text.Trim() == "")
687 {
688 _sLuong = "0";
689 }
690 else
691 {
692 _sLuong = txtSoLuong.Text.Replace(",", "");
693 }
694
695 if (txtGiaNhap.Text.Trim() == "")
696 {
697 _gNhap = "0";
698 }
699 else
700 {
701 _gNhap = txtGiaNhap.Text.Replace(",", "");
702 }
703
704 ulong _thanhTien = ulong.Parse(_sLuong) * ulong.Parse(_gNhap);
705
706 if(_sLuong == "0" || _gNhap == "0")
707 {
708 lblThanhTien.Text = "";
709 }
710 else
711 {
712 tTien = string.Format("{0:#,#}", _thanhTien);
713 lblThanhTien.Text = "Thành tiền: "+ tTien;
714 }
715 }
716
717 private void txtSoLuong_TextChanged(object sender, EventArgs e)
718 {
719 try
720 {
721 string value = txtSoLuong.Text.Replace(",", "");
722 ulong ul;
723 if (ulong.TryParse(value, out ul))
724 {
725 txtSoLuong.TextChanged -= txtSoLuong_TextChanged;
726 txtSoLuong.Text = string.Format("{0:#,#}", ul);
727 txtSoLuong.SelectionStart = txtSoLuong.Text.Length;
728 txtSoLuong.TextChanged += txtSoLuong_TextChanged;
729 }
730 }
731 catch
732 {
733 //ExceptionkeeperBll.LogFileWrite(ex);
734 }
735
736 ThanhTien(txtSoLuong.Text.Trim(), txtGiaNhap.Text.Trim());
737 }
738
739 private void btnXoaTam_Click(object sender, EventArgs e)
740 {
741 clearThongTinLienHe();
742 }
743
744 //Hiển thị số thứ tự trong row STT
745 private void dgvDanhSachNhapKho_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
746 {
747 //this.dgvDanhSachNhapKho.Rows[e.RowIndex].Cells["STT"].Value = (e.RowIndex + 1).ToString();
748 }
749
750
751
752 private void txtMaSanPham_KeyDown(object sender, KeyEventArgs e)
753 {
754 if (e.KeyCode == Keys.Enter)
755 {
756 //Không phát tiếng kêu
757 e.SuppressKeyPress = true;
758
759 //Hiển thị các form nhập
760 HienThiControl(true);
761
762 //Tìm trong bảng nhập kho
763 //Trong bảng nhập kho không có tìm trong bảng thông tin sản phẩm
764 //dt = Controllers.NhapKhoCtrl.FillDataSet_NhapKhoGetByMaSanPham(txtMaSanPham.Text.Trim()).Tables[0];
765
766 if (dt.Rows.Count > 0)
767 {
768 sanpham_cotrongttsp = false;
769
770 _tenSanPham = dt.Rows[0]["TenSanPham"].ToString();
771 _soLuong = 1;
772 _tenDonViTinh = dt.Rows[0]["TenDonViTinh"].ToString();
773 _giaNhap = dt.Rows[0]["GiaNhap"].ToString();
774 _ngaySanXuat = dt.Rows[0]["NgaySanXuat"].ToString();
775 _hanSuDung = dt.Rows[0]["HanSuDung"].ToString();
776 _ghiChu = dt.Rows[0]["GhiChu"].ToString();
777 _hoVaTen = dt.Rows[0]["HoVaTen"].ToString();
778 _soDienThoai = dt.Rows[0]["SoDienThoai"].ToString();
779 _diaChi = dt.Rows[0]["DiaChi"].ToString();
780 _giaBanLe = dt.Rows[0]["GiaBanLe"].ToString();
781 _giaBanBuon = dt.Rows[0]["GiaBanBuon"].ToString();
782
783 this.HienThiRaTextBox_ByGetDaTa(_tenSanPham, _soLuong, _tenDonViTinh, _giaNhap, _hanSuDung, _ngaySanXuat, _ghiChu, _hoVaTen, _soDienThoai, _diaChi, _giaBanLe, _giaBanBuon);
784 }
785 else
786 {
787 dt = Controllers.ThongTinSanPhamCtrl.FillDataSet_ThongTinSanPhamByMaSanPham(txtMaSanPham.Text.Trim()).Tables[0];
788 if (dt.Rows.Count > 0)
789 {
790
791 sanpham_cotrongttsp = true;
792
793 _tenSanPham = dt.Rows[0]["TenSanPham"].ToString();
794 _soLuong = 1;
795 _tenDonViTinh = dt.Rows[0]["TenDonViTinh"].ToString();
796 _giaNhap = string.Empty;
797 _ngaySanXuat = string.Empty;
798 _hanSuDung = string.Empty;
799 _ghiChu = string.Empty;
800 _hoVaTen = string.Empty;
801 _soDienThoai = string.Empty;
802 _diaChi = string.Empty;
803 _giaBanLe = string.Empty;
804 _giaBanBuon = string.Empty;
805
806 this.HienThiRaTextBox_ByGetDaTa(_tenSanPham, _soLuong, _tenDonViTinh, _giaNhap, _hanSuDung, _ngaySanXuat, _ghiChu, _hoVaTen, _soDienThoai, _diaChi, _giaBanLe, _giaBanBuon);
807
808 }
809 else
810 {
811 sanpham_cotrongttsp = false;
812 this.clearThongTinSanPham();
813 }
814 }
815
816 }
817 }
818
819 private void txtGiaBanLe_TextChanged(object sender, EventArgs e)
820 {
821 try
822 {
823 string value = txtGiaBanLe.Text.Replace(",", "");
824 ulong ul;
825 if (ulong.TryParse(value, out ul))
826 {
827 txtGiaBanLe.TextChanged -= txtGiaBanLe_TextChanged;
828 txtGiaBanLe.Text = string.Format("{0:#,#}", ul);
829 txtGiaBanLe.SelectionStart = txtGiaBanLe.Text.Length;
830 txtGiaBanLe.TextChanged += txtGiaBanLe_TextChanged;
831 }
832 }
833 catch
834 {
835 //ExceptionkeeperBll.LogFileWrite(ex);
836 }
837 }
838
839 private void txtGiaBanBuon_TextChanged(object sender, EventArgs e)
840 {
841 try
842 {
843 string value = txtGiaBanBuon.Text.Replace(",", "");
844 ulong ul;
845 if (ulong.TryParse(value, out ul))
846 {
847 txtGiaBanBuon.TextChanged -= txtGiaBanBuon_TextChanged;
848 txtGiaBanBuon.Text = string.Format("{0:#,#}", ul);
849 txtGiaBanBuon.SelectionStart = txtGiaBanBuon.Text.Length;
850 txtGiaBanBuon.TextChanged += txtGiaBanBuon_TextChanged;
851 }
852 }
853 catch
854 {
855 //ExceptionkeeperBll.LogFileWrite(ex);
856 }
857 }
858
859 private void txtGiaBanLe_KeyPress(object sender, KeyPressEventArgs e)
860 {
861 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
862 {
863 e.Handled = true;
864 }
865
866 // only allow one decimal point
867 if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
868 {
869 e.Handled = true;
870 }
871 }
872
873 private void txtGiaBanBuon_KeyPress(object sender, KeyPressEventArgs e)
874 {
875 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
876 {
877 e.Handled = true;
878 }
879
880 // only allow one decimal point
881 if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
882 {
883 e.Handled = true;
884 }
885 }
886
887 private void btnTimKiem_Click(object sender, EventArgs e)
888 {
889
890 }
891
892 private void txtSoDienThoai_KeyDown(object sender, KeyEventArgs e)
893 {
894 if (e.KeyCode == Keys.Enter)
895 {
896 e.SuppressKeyPress = true;
897 this.btnThemMoi_Click(sender, e);
898 }
899 }
900
901 private void btnTimKhachHang_Click(object sender, EventArgs e)
902 {
903 _soDienThoai = txtSoDienThoai.Text.Trim();
904
905 //dt = Controllers.NhapKhoCtrl.FillDataSet_getNhapKhoBySoDienThoai("", _soDienThoai).Tables[0];
906 if (dt.Rows.Count > 0)
907 {
908 txtHoTen.Text = dt.Rows[0]["HoVaTen"].ToString();
909 txtDiaChi.Text = dt.Rows[0]["DiaChi"].ToString();
910 }
911 else
912 {
913 txtHoTen.Text = "";
914 txtDiaChi.Text = "";
915 }
916 }
917
918 private void tabDanhSachNhapKho_Selected(object sender, TabControlEventArgs e)
919 {
920 if (e.TabPage == tabPageDanhSachNhapKho)
921 {
922 btnXoa.Enabled = true;
923 btnSua.Enabled = true;
924
925
926 pnlPhanTrang.Visible = true;
927 HienThiDanhSachNhapKho();
928
929 }
930 else
931 {
932 btnSua.Enabled = false;
933 btnXoa.Enabled = false;
934 pnlPhanTrang.Visible = false;
935 }
936 }
937
938 private void btnTiep_Click(object sender, EventArgs e)
939 {
940 if (_tongSoBanGhi > (_pageSize * _pageIndex))
941 {
942 _pageIndex = _pageIndex + 1;
943 this.HienThiDanhSachNhapKho();
944
945 }
946 else
947 {
948 return;
949 }
950 }
951
952 private void btnSau_Click(object sender, EventArgs e)
953 {
954 if ((_pageSize * _pageIndex) > _pageSize)
955 {
956 _pageIndex = _pageIndex - 1;
957 _stt = _pageSize * _pageIndex - _pageSize;
958 this.HienThiDanhSachNhapKho();
959
960
961 }
962 else
963 {
964 _pageIndex = 1;
965 }
966 }
967
968 private void cmbSoDongHienThi_SelectionChangeCommitted(object sender, EventArgs e)
969 {
970 _pageSize = Int32.Parse(cmbSoDongHienThi.SelectedItem.ToString());
971 _stt = 0;
972 this.HienThiDanhSachNhapKho();
973
974 }
975
976 private void dgvDanhSachNhapKho_CellClick(object sender, DataGridViewCellEventArgs e)
977 {
978 if (e.ColumnIndex == 17)
979 {
980 this.HienThiControl(true);
981
982 _idNhapKho = Int32.Parse(dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[0].Value.ToString());
983 txtMaSanPham.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[2].Value.ToString();
984 txtTenSanPham.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[3].Value.ToString();
985 txtSoLuong.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[4].Value.ToString();
986 cmbDonViTinh.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[5].Value.ToString();
987 txtGiaNhap.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[6].Value.ToString();
988 txtHanSuDung.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[8].Value.ToString();
989 txtNgaySanXuat.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[9].Value.ToString();
990 txtHoTen.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[10].Value.ToString();
991 txtSoDienThoai.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[11].Value.ToString();
992 txtDiaChi.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[12].Value.ToString();
993 txtGhiChu.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[13].Value.ToString();
994 txtGiaBanLe.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[14].Value.ToString();
995 txtGiaBanBuon.Text = dgvDanhSachNhapKho.Rows[e.RowIndex].Cells[15].Value.ToString();
996 }
997
998 }
999
1000
1001
1002 }
1003 }